
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>重构 · 《Terraform入门教程》</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="大可不加冰">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism-vsc-dark-plus.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.5.设计新模块的模式.html" />
    
    
    <link rel="prev" href="4.3.模块元参数.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.1.</b>
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="1.Terraform初步体验.html">
            
                <a href="1.Terraform初步体验.html">
            
                    
                        <b>1.2.</b>
                    
                    Terraform 初步体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                        <b>1.3.</b>
                    
                    Terraform基础概念
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="2.1.Terraform基础概念——Provider.html">
            
                <a href="2.1.Terraform基础概念——Provider.html">
            
                    
                        <b>1.3.1.</b>
                    
                    Provider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="2.2.Terraform基础概念——状态管理.html">
            
                <a href="2.2.Terraform基础概念——状态管理.html">
            
                    
                        <b>1.3.2.</b>
                    
                    状态管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="3.Terraform代码的书写.html">
            
                <a href="3.Terraform代码的书写.html">
            
                    
                        <b>1.4.</b>
                    
                    Terraform 代码的书写
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="3.1.类型.html">
            
                <a href="3.1.类型.html">
            
                    
                        <b>1.4.1.</b>
                    
                    类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="3.2.配置语法.html">
            
                <a href="3.2.配置语法.html">
            
                    
                        <b>1.4.2.</b>
                    
                    配置语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="3.3.输入变量.html">
            
                <a href="3.3.输入变量.html">
            
                    
                        <b>1.4.3.</b>
                    
                    输入变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="3.4.输出值.html">
            
                <a href="3.4.输出值.html">
            
                    
                        <b>1.4.4.</b>
                    
                    输出值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="3.5.局部值.html">
            
                <a href="3.5.局部值.html">
            
                    
                        <b>1.4.5.</b>
                    
                    局部值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="3.6.资源.html">
            
                <a href="3.6.资源.html">
            
                    
                        <b>1.4.6.</b>
                    
                    资源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="3.7.数据源.html">
            
                <a href="3.7.数据源.html">
            
                    
                        <b>1.4.7.</b>
                    
                    数据源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="3.8.表达式.html">
            
                <a href="3.8.表达式.html">
            
                    
                        <b>1.4.8.</b>
                    
                    表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="3.9.重载文件.html">
            
                <a href="3.9.重载文件.html">
            
                    
                        <b>1.4.9.</b>
                    
                    重载文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="3.10.代码风格规范.html">
            
                <a href="3.10.代码风格规范.html">
            
                    
                        <b>1.4.10.</b>
                    
                    代码风格规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="3.11.checks.html">
            
                <a href="3.11.checks.html">
            
                    
                        <b>1.4.11.</b>
                    
                    Checks
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="4.Terraform模块.html">
            
                <a href="4.Terraform模块.html">
            
                    
                        <b>1.5.</b>
                    
                    Terraform 模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="4.1.创建模块.html">
            
                <a href="4.1.创建模块.html">
            
                    
                        <b>1.5.1.</b>
                    
                    创建模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="4.2.使用模块.html">
            
                <a href="4.2.使用模块.html">
            
                    
                        <b>1.5.2.</b>
                    
                    使用模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="4.3.模块元参数.html">
            
                <a href="4.3.模块元参数.html">
            
                    
                        <b>1.5.3.</b>
                    
                    模块元参数
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="4.4.重构.html">
            
                <a href="4.4.重构.html">
            
                    
                        <b>1.5.4.</b>
                    
                    重构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="4.5.设计新模块的模式.html">
            
                <a href="4.5.设计新模块的模式.html">
            
                    
                        <b>1.5.5.</b>
                    
                    设计新模块的模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="5.Terraform命令行.html">
            
                <a href="5.Terraform命令行.html">
            
                    
                        <b>1.6.</b>
                    
                    Terraform 命令行
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="5.1.命令行配置文件.html">
            
                <a href="5.1.命令行配置文件.html">
            
                    
                        <b>1.6.1.</b>
                    
                    命令行配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="5.2.环境变量.html">
            
                <a href="5.2.环境变量.html">
            
                    
                        <b>1.6.2.</b>
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="5.3.资源地址.html">
            
                <a href="5.3.资源地址.html">
            
                    
                        <b>1.6.3.</b>
                    
                    资源地址
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="5.4.apply.html">
            
                <a href="5.4.apply.html">
            
                    
                        <b>1.6.4.</b>
                    
                    apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="5.5.console.html">
            
                <a href="5.5.console.html">
            
                    
                        <b>1.6.5.</b>
                    
                    console
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="5.6.destroy.html">
            
                <a href="5.6.destroy.html">
            
                    
                        <b>1.6.6.</b>
                    
                    destroy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="5.7.fmt.html">
            
                <a href="5.7.fmt.html">
            
                    
                        <b>1.6.7.</b>
                    
                    fmt
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="5.8.force-unlock.html">
            
                <a href="5.8.force-unlock.html">
            
                    
                        <b>1.6.8.</b>
                    
                    force-unlock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="5.9.get.html">
            
                <a href="5.9.get.html">
            
                    
                        <b>1.6.9.</b>
                    
                    get
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="5.10.graph.html">
            
                <a href="5.10.graph.html">
            
                    
                        <b>1.6.10.</b>
                    
                    graph
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="5.11.import.html">
            
                <a href="5.11.import.html">
            
                    
                        <b>1.6.11.</b>
                    
                    import
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="5.12.init.html">
            
                <a href="5.12.init.html">
            
                    
                        <b>1.6.12.</b>
                    
                    init
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="5.13.output.html">
            
                <a href="5.13.output.html">
            
                    
                        <b>1.6.13.</b>
                    
                    output
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="5.14.plan.html">
            
                <a href="5.14.plan.html">
            
                    
                        <b>1.6.14.</b>
                    
                    plan
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15" data-path="5.15.providers.html">
            
                <a href="5.15.providers.html">
            
                    
                        <b>1.6.15.</b>
                    
                    providers
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.15.1" data-path="5.15.1.mirror.html">
            
                <a href="5.15.1.mirror.html">
            
                    
                        <b>1.6.15.1.</b>
                    
                    mirror
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15.2" data-path="5.15.2.schema.html">
            
                <a href="5.15.2.schema.html">
            
                    
                        <b>1.6.15.2.</b>
                    
                    schema
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.16" data-path="5.16.refresh.html">
            
                <a href="5.16.refresh.html">
            
                    
                        <b>1.6.16.</b>
                    
                    refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.17" data-path="5.17.show.html">
            
                <a href="5.17.show.html">
            
                    
                        <b>1.6.17.</b>
                    
                    show
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18" data-path="5.18.state.html">
            
                <a href="5.18.state.html">
            
                    
                        <b>1.6.18.</b>
                    
                    state
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.18.1" data-path="5.18.1.list.html">
            
                <a href="5.18.1.list.html">
            
                    
                        <b>1.6.18.1.</b>
                    
                    list
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.2" data-path="5.18.2.mv.html">
            
                <a href="5.18.2.mv.html">
            
                    
                        <b>1.6.18.2.</b>
                    
                    mv
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.3" data-path="5.18.3.pull.html">
            
                <a href="5.18.3.pull.html">
            
                    
                        <b>1.6.18.3.</b>
                    
                    pull
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.4" data-path="5.18.4.push.html">
            
                <a href="5.18.4.push.html">
            
                    
                        <b>1.6.18.4.</b>
                    
                    push
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.5" data-path="5.18.5.replace-provider.html">
            
                <a href="5.18.5.replace-provider.html">
            
                    
                        <b>1.6.18.5.</b>
                    
                    replace-provider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.6" data-path="5.18.6.rm.html">
            
                <a href="5.18.6.rm.html">
            
                    
                        <b>1.6.18.6.</b>
                    
                    rm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.7" data-path="5.18.7.show.html">
            
                <a href="5.18.7.show.html">
            
                    
                        <b>1.6.18.7.</b>
                    
                    show
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.19" data-path="5.19.taint.html">
            
                <a href="5.19.taint.html">
            
                    
                        <b>1.6.19.</b>
                    
                    taint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.20" data-path="5.20.validate.html">
            
                <a href="5.20.validate.html">
            
                    
                        <b>1.6.20.</b>
                    
                    validate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.21" data-path="5.21.untaint.html">
            
                <a href="5.21.untaint.html">
            
                    
                        <b>1.6.21.</b>
                    
                    untaint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22" data-path="5.22.workspace.html">
            
                <a href="5.22.workspace.html">
            
                    
                        <b>1.6.22.</b>
                    
                    workspace
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.22.1" data-path="5.22.1.list.html">
            
                <a href="5.22.1.list.html">
            
                    
                        <b>1.6.22.1.</b>
                    
                    list
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.2" data-path="5.22.2.select.html">
            
                <a href="5.22.2.select.html">
            
                    
                        <b>1.6.22.2.</b>
                    
                    select
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.3" data-path="5.22.3.new.html">
            
                <a href="5.22.3.new.html">
            
                    
                        <b>1.6.22.3.</b>
                    
                    new
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.4" data-path="5.22.4.delete.html">
            
                <a href="5.22.4.delete.html">
            
                    
                        <b>1.6.22.4.</b>
                    
                    delete
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.5" data-path="5.22.5.show.html">
            
                <a href="5.22.5.show.html">
            
                    
                        <b>1.6.22.5.</b>
                    
                    show
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="6.test.html">
            
                <a href="6.test.html">
            
                    
                        <b>1.7.</b>
                    
                    Terraform Test
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="7.Aha——会心一击.html">
            
                <a href="7.Aha——会心一击.html">
            
                    
                        <b>1.8.</b>
                    
                    Aha——会心一击
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="7.1.有条件创建.html">
            
                <a href="7.1.有条件创建.html">
            
                    
                        <b>1.8.1.</b>
                    
                    有条件创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="7.2.依赖反转.html">
            
                <a href="7.2.依赖反转.html">
            
                    
                        <b>1.8.2.</b>
                    
                    依赖反转
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="7.3.多可用区分布.html">
            
                <a href="7.3.多可用区分布.html">
            
                    
                        <b>1.8.3.</b>
                    
                    多可用区分布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="7.4.provisioner与user_data.html">
            
                <a href="7.4.provisioner与user_data.html">
            
                    
                        <b>1.8.4.</b>
                    
                    provisioner与user_data
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="7.5.destroy-provisioner中使用变量.html">
            
                <a href="7.5.destroy-provisioner中使用变量.html">
            
                    
                        <b>1.8.5.</b>
                    
                    destroy-provisioner中使用变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="7.6.利用null_resource的triggers触发其他资源更新.html">
            
                <a href="7.6.利用null_resource的triggers触发其他资源更新.html">
            
                    
                        <b>1.8.6.</b>
                    
                    利用null_resource的triggers触发其他资源更新
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="7.7.利用null_resource搭配replace_triggered_by更新无法读取的属性.html">
            
                <a href="7.7.利用null_resource搭配replace_triggered_by更新无法读取的属性.html">
            
                    
                        <b>1.8.7.</b>
                    
                    利用 null_resource 搭配 replace_triggered_by 更新无法从服务端读取内容的属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="7.8.创建资源的条件依赖另一个资源的输出时怎么办.html">
            
                <a href="7.8.创建资源的条件依赖另一个资源的输出时怎么办.html">
            
                    
                        <b>1.8.8.</b>
                    
                    创建资源的条件依赖另一个资源的输出时怎么办
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="7.9.利用create_before_destroy调整资源update执行的顺序.html">
            
                <a href="7.9.利用create_before_destroy调整资源update执行的顺序.html">
            
                    
                        <b>1.8.9.</b>
                    
                    利用 create_before_destroy 调整资源 Update 的执行顺序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="7.10.terraform与自动化.html">
            
                <a href="7.10.terraform与自动化.html">
            
                    
                        <b>1.8.10.</b>
                    
                    Terraform 与自动化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="8.CloudPosse最佳实践.html">
            
                <a href="8.CloudPosse最佳实践.html">
            
                    
                        <b>1.9.</b>
                    
                    来自CloudPosse的Terraform最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="9.后记.html">
            
                <a href="9.后记.html">
            
                    
                        <b>1.10.</b>
                    
                    后记
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >重构</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x91CD;&#x6784;"><b>1.5.4.1. </b>&#x91CD;&#x6784;</a></li><ul><li><span class="title-icon "></span><a href="#moved-&#x5757;&#x8BED;&#x6CD5;"><b>1.5.4.1.1. </b>moved &#x5757;&#x8BED;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;"><b>1.5.4.1.2. </b>&#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;</a></li><li><span class="title-icon "></span><a href="#&#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><b>1.5.4.1.3. </b>&#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0; count &#x6216; for_each &#x58F0;&#x660E;</a></li><li><span class="title-icon "></span><a href="#&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;"><b>1.5.4.1.4. </b>&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;</a></li><li><span class="title-icon "></span><a href="#&#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><b>1.5.4.1.5. </b>&#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0; count &#x6216; for_each &#x58F0;&#x660E;</a></li><li><span class="title-icon "></span><a href="#&#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;"><b>1.5.4.1.6. </b>&#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;</a></li><li><span class="title-icon "></span><a href="#&#x5220;&#x9664;-moved-&#x5757;"><b>1.5.4.1.7. </b>&#x5220;&#x9664; moved &#x5757;</a></li></ul></ul></div><a href="#&#x91CD;&#x6784;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x91CD;&#x6784;"><a name="&#x91CD;&#x6784;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x6784;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1. &#x91CD;&#x6784;</h1>
<p>&#x8BF7;&#x6CE8;&#x610F;&#xFF0C;&#x672C;&#x8282;&#x4ECB;&#x7ECD;&#x7684;&#x901A;&#x8FC7; <code>moved</code> &#x5757;&#x8FDB;&#x884C;&#x6A21;&#x5757;&#x91CD;&#x6784;&#x7684;&#x529F;&#x80FD;&#x662F;&#x4ECE; Terraform v1.1 &#x5F00;&#x59CB;&#x88AB;&#x5F15;&#x5165;&#x7684;&#x3002;&#x5982;&#x679C;&#x8981;&#x5728;&#x4E4B;&#x524D;&#x7684;&#x7248;&#x672C;&#x8FDB;&#x884C;&#x8FD9;&#x6837;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5FC5;&#x987B;&#x901A;&#x8FC7; <a href="5.18.2.mv.html"><code>terraform state mv</code></a> &#x547D;&#x4EE4;&#x6765;&#x5B8C;&#x6210;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x4E00;&#x4E9B;&#x65E8;&#x5728;&#x88AB;&#x4EBA;&#x590D;&#x7528;&#x7684;&#x8001;&#x6A21;&#x5757;&#x6765;&#x8BF4;&#xFF0C;&#x6700;&#x521D;&#x7684;&#x6A21;&#x5757;&#x7ED3;&#x6784;&#x548C;&#x8D44;&#x6E90;&#x540D;&#x79F0;&#x53EF;&#x80FD;&#x4F1A;&#x9010;&#x6E10;&#x53D8;&#x5F97;&#x4E0D;&#x518D;&#x5408;&#x9002;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x80FD;&#x53D1;&#x73B0;&#x5C06;&#x4EE5;&#x524D;&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x4E24;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x6A21;&#x5757;&#x4F1A;&#x66F4;&#x5408;&#x7406;&#xFF0C;&#x8FD9;&#x9700;&#x8981;&#x5C06;&#x73B0;&#x6709;&#x8D44;&#x6E90;&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x96C6;&#x79FB;&#x52A8;&#x5230;&#x65B0;&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x3002;</p>
<p>Terraform &#x5C06;&#x4EE5;&#x524D;&#x7684;&#x72B6;&#x6001;&#x4E0E;&#x65B0;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#xFF0C;&#x8D44;&#x6E90;&#x4E0E;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x6216;&#x8D44;&#x6E90;&#x7684;&#x552F;&#x4E00;&#x5730;&#x5740;&#x76F8;&#x5173;&#x8054;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x79FB;&#x52A8;&#x6216;&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x4F1A;&#x88AB; Terraform &#x7406;&#x89E3;&#x4E3A;&#x9500;&#x6BC1;&#x65E7;&#x5730;&#x5740;&#x7684;&#x5BF9;&#x8C61;&#x5E76;&#x5728;&#x65B0;&#x5730;&#x5740;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x6DFB;&#x52A0; <code>moved</code> &#x5757;&#x4EE5;&#x8BB0;&#x5F55;&#x6211;&#x4EEC;&#x79FB;&#x52A8;&#x6216;&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x8C61;&#x8FC7;&#x53BB;&#x7684;&#x5730;&#x5740;&#x65F6;&#xFF0C;Terraform &#x4F1A;&#x5C06;&#x65E7;&#x5730;&#x5740;&#x7684;&#x73B0;&#x6709;&#x5BF9;&#x8C61;&#x89C6;&#x4E3A;&#x73B0;&#x5728;&#x5C5E;&#x4E8E;&#x65B0;&#x5730;&#x5740;&#x3002;</p>
<h2 id="moved-&#x5757;&#x8BED;&#x6CD5;"><a name="moved-&#x5757;&#x8BED;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#moved-&#x5757;&#x8BED;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.1. moved &#x5757;&#x8BED;&#x6CD5;</h2>
<p><code>moved</code> &#x5757;&#x53EA;&#x5305;&#x542B; <code>from</code> &#x548C; <code>to</code> &#x53C2;&#x6570;&#xFF0C;&#x6CA1;&#x6709;&#x540D;&#x79F0;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.b
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x6F14;&#x793A;&#x4E86;&#x6A21;&#x5757;&#x5148;&#x524D;&#x7248;&#x672C;&#x4E2D;&#x7684; <code>aws_instance.a</code> &#x5982;&#x4ECA;&#x4EE5; <code>aws_instance.b</code> &#x7684;&#x540D;&#x5B57;&#x5B58;&#x5728;&#x3002;</p>
<p>&#x5728;&#x4E3A; <code>aws_instance.b</code> &#x521B;&#x5EFA;&#x65B0;&#x7684;&#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x4E4B;&#x524D;&#xFF0C;Terraform &#x4F1A;&#x9996;&#x5148;&#x68C0;&#x67E5;&#x5F53;&#x524D;&#x72B6;&#x6001;&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x5730;&#x5740;&#x4E3A; <code>aws_instance.a</code> &#x7684;&#x8BB0;&#x5F55;&#x3002;&#x5982;&#x679C;&#x5B58;&#x5728;&#x8BE5;&#x8BB0;&#x5F55;&#xFF0C;Terraform &#x4F1A;&#x5C06;&#x4E4B;&#x91CD;&#x547D;&#x540D;&#x4E3A; <code>aws_instance.b</code> &#x7136;&#x540E;&#x7EE7;&#x7EED;&#x521B;&#x5EFA;&#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x3002;&#x6700;&#x7EC8;&#x751F;&#x6210;&#x7684;&#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x4E2D;&#x8BE5;&#x5BF9;&#x8C61;&#x5C31;&#x597D;&#x50CF;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x662F;&#x4EE5; <code>aws_instance.b</code> &#x7684;&#x540D;&#x5B57;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#xFF0C;&#x9632;&#x6B62;&#x5B83;&#x5728;&#x6267;&#x884C;&#x53D8;&#x66F4;&#x65F6;&#x88AB;&#x5220;&#x9664;&#x3002;</p>
<p><code>from</code> &#x548C; <code>to</code> &#x7684;&#x5730;&#x5740;&#x4F7F;&#x7528;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x5730;&#x5740;&#x8BED;&#x6CD5;&#xFF0C;&#x8BE5;&#x8BED;&#x6CD5;&#x5141;&#x8BB8;&#x9009;&#x5B9A;&#x6A21;&#x5757;&#x3001;&#x8D44;&#x6E90;&#x4EE5;&#x53CA;&#x5B50;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x51E0;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x91CD;&#x6784;&#x573A;&#x666F;&#x4E2D;&#x6240;&#x9700;&#x8981;&#x7684;&#x5730;&#x5740;&#x8BED;&#x6CD5;&#xFF1A;</p>
<h2 id="&#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;"><a name="&#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.2. &#x91CD;&#x547D;&#x540D;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;</h2>
<p>&#x8003;&#x8651;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x4E2D;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;a&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">count</span> <span class="token punctuation">=</span> <span class="token number">2</span>

  <span class="token comment"># (resource-type-specific configuration)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x7B2C;&#x4E00;&#x6B21;&#x5E94;&#x7528;&#x8BE5;&#x4EE3;&#x7801;&#x65F6; Terraform &#x4F1A;&#x521B;&#x5EFA; <code>aws_instance.a[0]</code> &#x4EE5;&#x53CA; <code>aws_instance.a[1]</code>&#x3002;</p>
<p>&#x5982;&#x679C;&#x968F;&#x540E;&#x6211;&#x4EEC;&#x4FEE;&#x6539;&#x4E86;&#x8BE5;&#x8D44;&#x6E90;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x5E76;&#x4E14;&#x628A;&#x65E7;&#x540D;&#x5B57;&#x8BB0;&#x5F55;&#x5728;&#x4E00;&#x4E2A; <code>moved</code> &#x5757;&#x91CC;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;b&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">count</span> <span class="token punctuation">=</span> <span class="token number">2</span>

  <span class="token comment"># (resource-type-specific configuration)</span>
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.b
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F53;&#x4E0B;&#x4E00;&#x6B21;&#x5E94;&#x7528;&#x4F7F;&#x7528;&#x4E86;&#x8BE5;&#x6A21;&#x5757;&#x7684;&#x4EE3;&#x7801;&#x65F6;&#xFF0C;Terraform &#x4F1A;&#x628A;&#x6240;&#x6709;&#x5730;&#x5740;&#x4E3A; <code>aws_instance.a</code> &#x7684;&#x5BF9;&#x8C61;&#x770B;&#x4F5C;&#x662F;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x4EE5; <code>aws_instance.b</code> &#x7684;&#x540D;&#x5B57;&#x521B;&#x5EFA;&#x7684;&#xFF1A;<code>aws_instance.a[0]</code> &#x4F1A;&#x88AB;&#x770B;&#x4F5C;&#x662F; <code>aws_instance.b[0]</code>&#xFF0C;<code>aws_instance.a[1]</code> &#x4F1A;&#x88AB;&#x770B;&#x4F5C;&#x662F; <code>aws_instance.b[1]</code>&#x3002;</p>
<p>&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x6A21;&#x5757;&#x5B9E;&#x4F8B;&#x4E2D;&#xFF0C;&#x56E0;&#x4E3A;&#x4ECE;&#x6765;&#x5C31;&#x4E0D;&#x5B58;&#x5728; <code>aws_instance.a</code>&#xFF0C;&#x4E8E;&#x662F;&#x4F1A;&#x5FFD;&#x7565; <code>moved</code> &#x5757;&#x800C;&#x50CF;&#x901A;&#x5E38;&#x90A3;&#x6837;&#x76F4;&#x63A5;&#x521B;&#x5EFA; <code>aws_instance.b[0]</code> &#x4EE5;&#x53CA; <code>aws_instance.b[1]</code>&#x3002;</p>
<h2 id="&#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><a name="&#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;" class="anchor-navigation-ex-anchor" href="#&#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.3. &#x4E3A;&#x8D44;&#x6E90;&#x6DFB;&#x52A0; count &#x6216; for_each &#x58F0;&#x660E;</h2>
<p>&#x4E00;&#x5F00;&#x59CB;&#x4EE3;&#x7801;&#x4E2D;&#x6709;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x5355;&#x5B9E;&#x4F8B;&#x8D44;&#x6E90;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;a&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (resource-type-specific configuration)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5E94;&#x7528;&#x8BE5;&#x4EE3;&#x7801;&#x4F1A;&#x4F7F;&#x5F97; Terraform &#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#x4E3A; <code>aws_instance.a</code> &#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x968F;&#x540E;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x5728;&#x8BE5;&#x8D44;&#x6E90;&#x4E0A;&#x6DFB;&#x52A0; <a href="3.6.&#x8D44;&#x6E90;.html#for_each"><code>for_each</code></a> &#x6765;&#x521B;&#x5EFA;&#x591A;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;&#x4E3A;&#x4E86;&#x4FDD;&#x6301;&#x5148;&#x524D;&#x5173;&#x8054;&#x5230; <code>aws_instance.a</code> &#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;&#xFF0C;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; <code>moved</code> &#x5757;&#x6765;&#x6307;&#x5B9A;&#x65B0;&#x4EE3;&#x7801;&#x4E2D;&#x539F;&#x5148;&#x7684;&#x5BF9;&#x8C61;&#x5B9E;&#x4F8B;&#x6240;&#x5173;&#x8054;&#x7684;&#x952E;&#x662F;&#x4EC0;&#x4E48;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">locals</span> <span class="token punctuation">{</span>
  <span class="token property">instances</span> <span class="token punctuation">=</span> tomap(<span class="token punctuation">{</span>
    <span class="token property">big</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">instance_type</span> <span class="token punctuation">=</span> <span class="token string">&quot;m3.large&quot;</span>
    <span class="token punctuation">}</span>
    <span class="token property">small</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">instance_type</span> <span class="token punctuation">=</span> <span class="token string">&quot;t2.medium&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>)
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;a&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">for_each</span> <span class="token punctuation">=</span> local.instances

  <span class="token property">instance_type</span> <span class="token punctuation">=</span> each.value.instance_type
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.a<span class="token punctuation">[</span><span class="token string">&quot;small&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4F1A;&#x9632;&#x6B62; Terraform &#x5728;&#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x4E2D;&#x9500;&#x6BC1;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684; <code>aws_instance.a</code> &#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x5176;&#x770B;&#x4F5C;&#x662F;&#x4EE5; <code>aws_instance.a[&quot;small&quot;]</code> &#x7684;&#x5730;&#x5740;&#x521B;&#x5EFA;&#x7684;&#x3002;</p>
<p>&#x5F53; <code>moved</code> &#x5757;&#x7684;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x4E2D;&#x7684;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x5B9E;&#x4F8B;&#x952E;&#x65F6;&#xFF0C;&#x5982;&#x4E0A;&#x4F8B;&#x4E2D;&#x7684; <code>[&quot;small&quot;]</code>&#xFF0C;Terraform &#x5C06;&#x8FD9;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x7406;&#x89E3;&#x4E3A;&#x5F15;&#x7528;&#x8D44;&#x6E90;&#x7684;&#x7279;&#x5B9A;&#x5B9E;&#x4F8B;&#x800C;&#x4E0D;&#x662F;&#x6574;&#x4E2A;&#x8D44;&#x6E90;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x60A8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>moved</code> &#x5728;&#x952E;&#x4E4B;&#x95F4;&#x5207;&#x6362;&#x4EE5;&#x53CA;&#x5728; <code>count</code>&#x3001;<code>for_each</code> &#x4E4B;&#x95F4;&#x5207;&#x6362;&#x65F6;&#x6DFB;&#x52A0;&#x548C;&#x5220;&#x9664;&#x952E;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x6F14;&#x793A;&#x4E86;&#x51E0;&#x79CD;&#x5176;&#x4ED6;&#x7C7B;&#x4F3C;&#x7684;&#x8BB0;&#x5F55;&#x4E86;&#x8D44;&#x6E90;&#x5B9E;&#x4F8B;&#x952E;&#x53D8;&#x66F4;&#x7684;&#x5408;&#x6CD5; <code>moved</code> &#x5757;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token comment"># Both old and new configuration used &quot;for_each&quot;, but the</span>
<span class="token comment"># &quot;small&quot; element was renamed to &quot;tiny&quot;.</span>
<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.b<span class="token punctuation">[</span><span class="token string">&quot;small&quot;</span><span class="token punctuation">]</span>
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.b<span class="token punctuation">[</span><span class="token string">&quot;tiny&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment"># The old configuration used &quot;count&quot; and the new configuration</span>
<span class="token comment"># uses &quot;for_each&quot;, with the following mappings from</span>
<span class="token comment"># index to key:</span>
<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.c<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.c<span class="token punctuation">[</span><span class="token string">&quot;small&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.c<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.c<span class="token punctuation">[</span><span class="token string">&quot;tiny&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>

<span class="token comment"># The old configuration used &quot;count&quot;, and the new configuration</span>
<span class="token comment"># uses neither &quot;count&quot; nor &quot;for_each&quot;, and you want to keep</span>
<span class="token comment"># only the object at index 2.</span>
<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.d<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.d
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x539F;&#x5148;&#x6CA1;&#x6709;&#x58F0;&#x660E; <code>count</code> &#x7684;&#x8D44;&#x6E90;&#x4E0A;&#x6DFB;&#x52A0; <code>count</code> &#x65F6;&#xFF0C;Terraform &#x4F1A;&#x81EA;&#x52A8;&#x5C06;&#x539F;&#x5148;&#x7684;&#x5BF9;&#x8C61;&#x79FB;&#x52A8;&#x5230;&#x7B2C; 0 &#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x9664;&#x975E;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x4E00;&#x4E2A; <code>moved</code> &#x5757;&#x663E;&#x5F0F;&#x58F0;&#x660E;&#x8BE5;&#x8D44;&#x6E90;&#x3002;&#x7136;&#x800C;&#xFF0C;&#x6211;&#x4EEC;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528; <code>moved</code> &#x5757;&#x663E;&#x5F0F;&#x58F0;&#x660E;&#x8D44;&#x6E90;&#x7684;&#x79FB;&#x52A8;&#xFF0C;&#x4F7F;&#x5F97;&#x8BFB;&#x8005;&#x5728;&#x672A;&#x6765;&#x9605;&#x8BFB;&#x6A21;&#x5757;&#x7684;&#x4EE3;&#x7801;&#x65F6;&#x80FD;&#x591F;&#x66F4;&#x6E05;&#x695A;&#x5730;&#x4E86;&#x89E3;&#x5230;&#x8FD9;&#x4E9B;&#x53D8;&#x66F4;&#x3002;</p>
<h2 id="&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;"><a name="&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.4. &#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;</h2>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x7C7B;&#x4F3C;&#x91CD;&#x547D;&#x540D;&#x8D44;&#x6E90;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x91CD;&#x547D;&#x540D;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;&#x3002;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x7528;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#x8C03;&#x7528;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">module<span class="token type variable"> &quot;a&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/example&quot;</span>

  <span class="token comment"># (module arguments)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F53;&#x5E94;&#x7528;&#x8BE5;&#x4EE3;&#x7801;&#x65F6;&#xFF0C;Terraform &#x4F1A;&#x5728;&#x6A21;&#x5757;&#x5185;&#x58F0;&#x660E;&#x7684;&#x8D44;&#x6E90;&#x8DEF;&#x5F84;&#x524D;&#x9762;&#x52A0;&#x4E0A;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x8DEF;&#x5F84;&#x524D;&#x7F00; <code>module.a</code>&#x3002;&#x6BD4;&#x65B9;&#x8BF4;&#xFF0C;&#x6A21;&#x5757;&#x5185;&#x7684; <code>aws_instance.example</code> &#x7684;&#x5B8C;&#x6574;&#x5730;&#x5740;&#x4E3A; <code>module.a.aws_instance.example</code>&#x3002;</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x968F;&#x540E;&#x6253;&#x7B97;&#x4FEE;&#x6539;&#x6A21;&#x5757;&#x540D;&#x79F0;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4FEE;&#x6539; <code>module</code> &#x5757;&#x7684;&#x6807;&#x7B7E;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x4E00;&#x4E2A; <code>moved</code> &#x5757;&#x5185;&#x90E8;&#x8BB0;&#x5F55;&#x8BE5;&#x53D8;&#x66F4;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">module<span class="token type variable"> &quot;b&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/example&quot;</span>

  <span class="token comment"># (module arguments)</span>
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> module.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.b
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F53;&#x4E0B;&#x4E00;&#x6B21;&#x5E94;&#x7528;&#x5305;&#x542B;&#x8BE5;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x7684;&#x4EE3;&#x7801;&#x65F6;&#xFF0C;Terraform &#x4F1A;&#x5C06;&#x6240;&#x6709;&#x8DEF;&#x5F84;&#x524D;&#x7F00;&#x4E3A; <code>module.a</code> &#x7684;&#x5BF9;&#x8C61;&#x770B;&#x4F5C;&#x4ECE;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x662F;&#x4EE5; <code>module.b</code> &#x4E3A;&#x524D;&#x7F00;&#x521B;&#x5EFA;&#x7684;&#x3002;<code>module.a.aws_instance.example</code> &#x4F1A;&#x88AB;&#x770B;&#x4F5C;&#x662F; <code>module.b.aws_instance.example</code>&#x3002;</p>
<p>&#x8BE5;&#x4F8B;&#x5B50;&#x4E2D;&#x7684; <code>moved</code> &#x5757;&#x4E2D;&#x7684;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x90FD;&#x4EE3;&#x8868;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;&#xFF0C;&#x800C; Terraform &#x8BC6;&#x522B;&#x51FA;&#x5C06;&#x539F;&#x6A21;&#x5757;&#x5730;&#x5740;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x8D44;&#x6E90;&#x79FB;&#x52A8;&#x5230;&#x65B0;&#x7684;&#x6A21;&#x5757;&#x5730;&#x5740;&#x4E2D;&#x3002;&#x5982;&#x679C;&#x8BE5;&#x6A21;&#x5757;&#x58F0;&#x660E;&#x65F6;&#x4F7F;&#x7528;&#x4E86; <code>count</code> &#x6216;&#x662F; <code>for_each</code>&#xFF0C;&#x90A3;&#x4E48;&#x8BE5;&#x79FB;&#x52A8;&#x4E5F;&#x5C06;&#x88AB;&#x5E94;&#x7528;&#x4E8E;&#x6240;&#x6709;&#x7684;&#x5B9E;&#x4F8B;&#x4E0A;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x9010;&#x4E2A;&#x6307;&#x5B9A;&#x3002;</p>
<h2 id="&#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><a name="&#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;" class="anchor-navigation-ex-anchor" href="#&#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0;-count-&#x6216;-foreach-&#x58F0;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.5. &#x4E3A;&#x6A21;&#x5757;&#x8C03;&#x7528;&#x6DFB;&#x52A0; count &#x6216; for_each &#x58F0;&#x660E;</h2>
<p>&#x8003;&#x8651;&#x4E00;&#x4E0B;&#x5355;&#x5B9E;&#x4F8B;&#x7684;&#x6A21;&#x5757;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">module<span class="token type variable"> &quot;a&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/example&quot;</span>q

  <span class="token comment"># (module arguments)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5E94;&#x7528;&#x8BE5;&#x6BB5;&#x4EE3;&#x7801;&#x4F1A;&#x5BFC;&#x81F4; Terraform &#x521B;&#x5EFA;&#x7684;&#x8D44;&#x6E90;&#x5730;&#x5740;&#x90FD;&#x62E5;&#x6709; <code>module.a</code> &#x7684;&#x524D;&#x7F00;&#x3002;</p>
<p>&#x968F;&#x540E;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x518D;&#x901A;&#x8FC7;&#x6DFB;&#x52A0; <code>count</code> &#x6765;&#x521B;&#x5EFA;&#x591A;&#x4E2A;&#x8D44;&#x6E90;&#x5B9E;&#x4F8B;&#x3002;&#x4E3A;&#x4E86;&#x4FDD;&#x7559;&#x5148;&#x524D;&#x7684; <code>aws_instance.a</code> &#x5B9E;&#x4F8B;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; <code>moved</code> &#x5757;&#x6765;&#x8BBE;&#x7F6E;&#x5728;&#x65B0;&#x4EE3;&#x7801;&#x4E2D;&#x8BE5;&#x5B9E;&#x4F8B;&#x7684;&#x5BF9;&#x5E94;&#x7684;&#x952E;&#x3002;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">module<span class="token type variable"> &quot;a&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/example&quot;</span>
  <span class="token property">count</span>  <span class="token punctuation">=</span> <span class="token number">3</span>

  <span class="token comment"># (module arguments)</span>
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> module.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.a<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5F15;&#x5BFC; Terraform &#x5C06;&#x6240;&#x6709; <code>module.a</code> &#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x770B;&#x4F5C;&#x662F;&#x4ECE;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x662F;&#x4EE5; <code>module.a[2]</code> &#x7684;&#x524D;&#x7F00;&#x88AB;&#x521B;&#x5EFA;&#x7684;&#x3002;&#x7ED3;&#x679C;&#x5C31;&#x5C31;&#x662F;&#xFF0C;Terraform &#x751F;&#x6210;&#x7684;&#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x4E2D;&#x53EA;&#x4F1A;&#x521B;&#x5EFA; <code>module.a[0]</code> &#x4EE5;&#x53CA; <code>module.a[1]</code>&#x3002;</p>
<p>&#x5F53; <code>moved</code> &#x5757;&#x7684;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x4E2D;&#x7684;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x5B9E;&#x4F8B;&#x952E;&#x65F6;&#xFF0C;&#x4F8B;&#x5982;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x4E2D;&#x7684; <code>[2]</code>&#x90A3;&#x6837;&#xFF0C;Terraform &#x4F1A;&#x7406;&#x89E3;&#x5C06;&#x8FD9;&#x4E24;&#x4E2A;&#x5730;&#x5740;&#x7406;&#x89E3;&#x4E3A;&#x5BF9;&#x6A21;&#x5757;&#x7684;&#x7279;&#x5B9A;&#x5B9E;&#x4F8B;&#x7684;&#x8C03;&#x7528;&#x800C;&#x975E;&#x5BF9;&#x6A21;&#x5757;&#x6240;&#x6709;&#x5B9E;&#x4F8B;&#x7684;&#x8C03;&#x7528;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>moved</code> &#x5757;&#x5728;&#x4E0D;&#x540C;&#x952E;&#x4E4B;&#x95F4;&#x5207;&#x6362;&#x6765;&#x6DFB;&#x52A0;&#x6216;&#x662F;&#x5220;&#x9664;&#x952E;&#xFF0C;&#x8BE5;&#x673A;&#x5236;&#x53EF;&#x7528;&#x4E8E; <code>count</code> &#x548C; <code>for_each</code>&#xFF0C;&#x6216;&#x5220;&#x9664;&#x6A21;&#x5757;&#x4E0A;&#x7684;&#x8FD9;&#x79CD;&#x58F0;&#x660E;&#x3002;</p>
<h2 id="&#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;"><a name="&#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;" class="anchor-navigation-ex-anchor" href="#&#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.6. &#x5C06;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5206;&#x5272;&#x6210;&#x591A;&#x4E2A;&#x6A21;&#x5757;</h2>
<p>&#x968F;&#x7740;&#x6A21;&#x5757;&#x63D0;&#x4F9B;&#x7684;&#x529F;&#x80FD;&#x8D8A;&#x6765;&#x8D8A;&#x591A;&#xFF0C;&#x6700;&#x7EC8;&#x6A21;&#x5757;&#x53EF;&#x80FD;&#x53D8;&#x5F97;&#x8FC7;&#x5927;&#x800C;&#x4E0D;&#x5F97;&#x4E0D;&#x5C06;&#x4E4B;&#x62C6;&#x5206;&#x6210;&#x4E24;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x6A21;&#x5757;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x4E0B;&#x4E0B;&#x9762;&#x7684;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;a&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;b&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;c&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x8BE5;&#x6A21;&#x5757;&#x5206;&#x5272;&#x4E3A;&#x4E09;&#x4E2A;&#x90E8;&#x5206;&#xFF1A;</p>
<ul>
<li><code>aws_instance.a</code> &#x73B0;&#x5728;&#x5F52;&#x5C5E;&#x4E8E;&#x6A21;&#x5757; &quot;x&quot;&#x3002;</li>
<li><code>aws_instance.b</code> &#x4E5F;&#x5C5E;&#x4E8E;&#x6A21;&#x5757; &quot;x&quot;&#x3002;</li>
<li><code>aws_instance.c</code> &#x73B0;&#x5728;&#x5F52;&#x5C5E;&#x4E8E;&#x6A21;&#x5757; &quot;y&quot;&#x3002;</li>
</ul>
<p>&#x8981;&#x5728;&#x4E0D;&#x66FF;&#x6362;&#x7ED1;&#x5B9A;&#x5230;&#x65E7;&#x8D44;&#x6E90;&#x5730;&#x5740;&#x7684;&#x73B0;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x5B9E;&#x73B0;&#x6B64;&#x91CD;&#x6784;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#xFF1A;</p>
<ol>
<li>&#x7F16;&#x5199;&#x6A21;&#x5757; &quot;x&quot;&#xFF0C;&#x5C06;&#x5C5E;&#x4E8E;&#x5B83;&#x7684;&#x4E24;&#x4E2A;&#x8D44;&#x6E90;&#x62F7;&#x8D1D;&#x8FC7;&#x53BB;&#x3002;</li>
<li>&#x7F16;&#x5199;&#x6A21;&#x5757; &quot;y&quot;&#xFF0C;&#x5C06;&#x5C5E;&#x4E8E;&#x5B83;&#x7684;&#x4E00;&#x4E2A;&#x8D44;&#x6E90;&#x62F7;&#x8D1D;&#x8FC7;&#x53BB;&#x3002;</li>
<li>&#x7F16;&#x8F91;&#x539F;&#x6709;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#xFF0C;&#x5220;&#x9664;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#xFF0C;&#x53EA;&#x5305;&#x542B;&#x6709;&#x5173;&#x8FC1;&#x79FB;&#x73B0;&#x6709;&#x8D44;&#x6E90;&#x7684;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x7684;&#x914D;&#x7F6E;&#x4EE3;&#x7801;&#x3002;</li>
</ol>
<p>&#x65B0;&#x7684;&#x6A21;&#x5757; &quot;x&quot; &#x548C; &quot;y&quot; &#x5E94;&#x8BE5;&#x53EA;&#x5305;&#x542B; <code>resource</code> &#x5757;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token comment"># module &quot;x&quot;</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;a&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;b&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-hcl"><span class="token comment"># module &quot;y&quot;</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;c&quot;</span> <span class="token punctuation">{</span>
  <span class="token comment"># (other resource-type-specific configuration)</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x800C;&#x539F;&#x6709;&#x6A21;&#x5757;&#x5219;&#x88AB;&#x4FEE;&#x6539;&#x6210;&#x53EA;&#x5305;&#x542B;&#x6709;&#x5411;&#x4E0B;&#x517C;&#x5BB9;&#x903B;&#x8F91;&#x7684;&#x57AB;&#x7247;&#xFF0C;&#x8C03;&#x7528;&#x4E24;&#x4E2A;&#x65B0;&#x6A21;&#x5757;&#xFF0C;&#x5E76;&#x4F7F;&#x7528; <code>moved</code> &#x5757;&#x5B9A;&#x4E49;&#x54EA;&#x4E9B;&#x8D44;&#x6E90;&#x88AB;&#x79FB;&#x52A8;&#x5230;&#x65B0;&#x6A21;&#x5757;&#x4E2D;&#x53BB;&#x4E86;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">module<span class="token type variable"> &quot;x&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/x&quot;</span>

  <span class="token comment"># ...</span>
<span class="token punctuation">}</span>

<span class="token keyword">module<span class="token type variable"> &quot;y&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;../modules/y&quot;</span>

  <span class="token comment"># ...</span>
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.x.aws_instance.a
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.b
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.x.aws_instance.b
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.c
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.y.aws_instance.c
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5F53;&#x4E00;&#x4E2A;&#x539F;&#x6A21;&#x5757;&#x7684;&#x8C03;&#x7528;&#x8005;&#x5347;&#x7EA7;&#x6A21;&#x5757;&#x7248;&#x672C;&#x5230;&#x8FD9;&#x4E2A;&#x201C;&#x57AB;&#x7247;&#x201D;&#x7248;&#x672C;&#x65F6;&#xFF0C;Terraform &#x4F1A;&#x6CE8;&#x610F;&#x5230;&#x8FD9;&#x4E9B; <code>moved</code> &#x5757;&#xFF0C;&#x5E76;&#x5C06;&#x90A3;&#x4E9B;&#x5173;&#x8054;&#x5230;&#x8001;&#x5730;&#x5740;&#x7684;&#x8D44;&#x6E90;&#x5BF9;&#x8C61;&#x770B;&#x4F5C;&#x662F;&#x4ECE;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x662F;&#x7531;&#x65B0;&#x6A21;&#x5757;&#x521B;&#x5EFA;&#x7684;&#x90A3;&#x6837;&#x3002;</p>
<p>&#x8BE5;&#x6A21;&#x5757;&#x7684;&#x65B0;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x57AB;&#x7247;&#x6A21;&#x5757;&#xFF0C;&#x6216;&#x662F;&#x72EC;&#x7ACB;&#x8C03;&#x7528;&#x4E24;&#x4E2A;&#x65B0;&#x6A21;&#x5757;&#x3002;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x901A;&#x77E5;&#x8001;&#x6A21;&#x5757;&#x7684;&#x73B0;&#x6709;&#x7528;&#x6237;&#x8001;&#x6A21;&#x5757;&#x5DF2;&#x88AB;&#x5E9F;&#x5F03;&#xFF0C;&#x4ED6;&#x4EEC;&#x5C06;&#x6765;&#x7684;&#x5F00;&#x53D1;&#x4E2D;&#x9700;&#x8981;&#x72EC;&#x7ACB;&#x4F7F;&#x7528;&#x8FD9;&#x4E24;&#x4E2A;&#x65B0;&#x6A21;&#x5757;&#x3002;</p>
<p>&#x591A;&#x6A21;&#x5757;&#x91CD;&#x6784;&#x7684;&#x573A;&#x666F;&#x662F;&#x4E0D;&#x591A;&#x89C1;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x8FDD;&#x53CD;&#x4E86;&#x7236;&#x6A21;&#x5757;&#x5C06;&#x5176;&#x5B50;&#x6A21;&#x5757;&#x89C6;&#x4E3A;&#x9ED1;&#x76D2;&#x7684;&#x5178;&#x578B;&#x89C4;&#x5219;&#xFF0C;&#x4E0D;&#x77E5;&#x9053;&#x5728;&#x5176;&#x4E2D;&#x58F0;&#x660E;&#x4E86;&#x54EA;&#x4E9B;&#x8D44;&#x6E90;&#x3002;&#x8FD9;&#x79CD;&#x59A5;&#x534F;&#x7684;&#x524D;&#x63D0;&#x662F;&#x5047;&#x8BBE;&#x6240;&#x6709;&#x8FD9;&#x4E09;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x7531;&#x540C;&#x4E00;&#x4E2A;&#x4EBA;&#x7EF4;&#x62A4;&#x5E76;&#x5206;&#x5E03;&#x5728;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5305;&#x4E2D;&#x3002;</p>
<p>&#x4E3A;&#x907F;&#x514D;&#x72EC;&#x7ACB;&#x6A21;&#x5757;&#x4E4B;&#x95F4;&#x7684;&#x8026;&#x5408;&#xFF0C;Terraform &#x53EA;&#x5141;&#x8BB8;&#x58F0;&#x660E;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6A21;&#x5757;&#x95F4;&#x7684;&#x79FB;&#x52A8;&#x3002;&#x6362;&#x53E5;&#x8BDD;&#x8BB2;&#xFF0C;Terraform &#x4E0D;&#x5141;&#x8BB8;&#x5C06;&#x8D44;&#x6E90;&#x79FB;&#x52A8;&#x5230;&#x4E00;&#x4E2A; <code>source</code> &#x5730;&#x5740;&#x4E0D;&#x662F;<a href="4.2.&#x4F7F;&#x7528;&#x6A21;&#x5757;.html#&#x672C;&#x5730;&#x8DEF;&#x5F84;">&#x672C;&#x5730;&#x8DEF;&#x5F84;</a>&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x53BB;&#x3002;</p>
<p>Terraform &#x4F7F;&#x7528;&#x5B9A;&#x4E49; <code>moved</code> &#x5757;&#x7684;&#x6A21;&#x5757;&#x5B9E;&#x4F8B;&#x7684;&#x5730;&#x5740;&#x7684;&#x5730;&#x5740;&#x6765;&#x89E3;&#x6790; <code>moved</code> &#x5757;&#x4E2D;&#x7684;&#x76F8;&#x5BF9;&#x5730;&#x5740;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x9762;&#x7684;&#x539F;&#x6A21;&#x5757;&#x5DF2;&#x7ECF;&#x662F;&#x540D;&#x4E3A; <code>module.original</code> &#x7684;&#x5B50;&#x6A21;&#x5757;&#xFF0C;&#x5219;&#x539F;&#x6A21;&#x5757;&#x4E2D;&#x5BF9; <code>module.x.aws_instance.a</code> &#x7684;&#x5F15;&#x7528;&#x5728;&#x6839;&#x6A21;&#x5757;&#x4E2D;&#x5C06;&#x88AB;&#x89E3;&#x6790;&#x4E3A; <code>module.original.module.x.aws_instance.a</code>&#x3002;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x53EA;&#x80FD;&#x9488;&#x5BF9;&#x5B83;&#x81EA;&#x8EAB;&#x6216;&#x662F;&#x5B83;&#x7684;&#x5B50;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x8D44;&#x6E90;&#x58F0;&#x660E; <code>moved</code> &#x5757;&#x3002;</p>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#x5F15;&#x7528;&#x5E26;&#x6709; <code>count</code> &#x6216; <code>for_each</code> &#x5143;&#x53C2;&#x6570;&#x7684;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x8D44;&#x6E90;&#xFF0C;&#x5219;&#x5FC5;&#x987B;&#x6307;&#x5B9A;&#x8981;&#x4F7F;&#x7528;&#x7684;&#x7279;&#x5B9A;&#x5B9E;&#x4F8B;&#x952E;&#x4EE5;&#x5339;&#x914D;&#x8D44;&#x6E90;&#x914D;&#x7F6E;&#x7684;&#x65B0;&#x4F4D;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.example
  <span class="token property">to</span>   <span class="token punctuation">=</span> module.new<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>.aws_instance.example
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x5220;&#x9664;-moved-&#x5757;"><a name="&#x5220;&#x9664;-moved-&#x5757;" class="anchor-navigation-ex-anchor" href="#&#x5220;&#x9664;-moved-&#x5757;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.4.1.7. &#x5220;&#x9664; moved &#x5757;</h2>
<p>&#x968F;&#x7740;&#x65F6;&#x95F4;&#x7684;&#x63A8;&#x79FB;&#xFF0C;&#x4E00;&#x4E9B;&#x8001;&#x6A21;&#x5757;&#x53EF;&#x80FD;&#x4F1A;&#x79EF;&#x7D2F;&#x5927;&#x91CF; <code>moved</code> &#x5757;&#x3002;</p>
<p>&#x5220;&#x9664; <code>moved</code> &#x5757;&#x901A;&#x5E38;&#x662F;&#x4E00;&#x79CD;&#x7834;&#x574F;&#x6027;&#x53D8;&#x66F4;&#xFF0C;&#x56E0;&#x4E3A;&#x5220;&#x9664;&#x540E;&#x6240;&#x6709;&#x4F7F;&#x7528;&#x65E7;&#x5730;&#x5740;&#x5F15;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x5C06;&#x88AB;&#x5220;&#x9664;&#x800C;&#x4E0D;&#x662F;&#x88AB;&#x79FB;&#x52A8;&#x3002;&#x6211;&#x4EEC;&#x5F3A;&#x70C8;&#x5EFA;&#x8BAE;&#x4FDD;&#x7559;&#x5386;&#x53F2;&#x4E0A;&#x6240;&#x6709;&#x7684; <code>moved</code> &#x5757;&#x6765;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x4ECE;&#x4EFB;&#x610F;&#x7248;&#x672C;&#x5347;&#x7EA7;&#x5230;&#x5F53;&#x524D;&#x7248;&#x672C;&#x7684;&#x5347;&#x7EA7;&#x8DEF;&#x5F84;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x51B3;&#x5B9A;&#x8981;&#x5220;&#x9664; <code>moved</code> &#x5757;&#xFF0C;&#x9700;&#x8981;&#x8C28;&#x614E;&#x884C;&#x4E8B;&#x3002;&#x5BF9;&#x4E8E;&#x7EC4;&#x7EC7;&#x5185;&#x90E8;&#x7684;&#x79C1;&#x6709;&#x6A21;&#x5757;&#x6765;&#x8BF4;&#x5220;&#x9664; <code>moved</code> &#x5757;&#x53EF;&#x80FD;&#x662F;&#x5B89;&#x5168;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x786E;&#x8BA4;&#x6240;&#x6709;&#x7528;&#x6237;&#x90FD;&#x5DF2;&#x7ECF;&#x4F7F;&#x7528;&#x65B0;&#x7248;&#x672C;&#x6A21;&#x5757;&#x4EE3;&#x7801;&#x8FD0;&#x884C;&#x8FC7; <code>terraform apply</code> &#x4E86;&#x3002;</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x591A;&#x6B21;&#x91CD;&#x547D;&#x540D;&#x6216;&#x662F;&#x79FB;&#x52A8;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x6211;&#x4EEC;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;<em>&#x4E32;&#x8054;</em>&#x7684; <code>moved</code> &#x5757;&#x6765;&#x8BB0;&#x5F55;&#x5B8C;&#x6574;&#x7684;&#x53D8;&#x66F4;&#x4FE1;&#x606F;&#xFF0C;&#x65B0;&#x7684;&#x5757;&#x5F15;&#x7528;&#x5DF2;&#x6709;&#x7684;&#x5757;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.a
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.b
<span class="token punctuation">}</span>

<span class="token keyword">moved</span> <span class="token punctuation">{</span>
  <span class="token property">from</span> <span class="token punctuation">=</span> aws_instance.b
  <span class="token property">to</span>   <span class="token punctuation">=</span> aws_instance.c
<span class="token punctuation">}</span>
</code></pre>
<p>&#x50CF;&#x8FD9;&#x6837;&#x8BB0;&#x5F55;&#x4E0B;&#x79FB;&#x52A8;&#x7684;&#x5E8F;&#x5217;&#x53EF;&#x4EE5;&#x4F7F; <code>aws_instance.a</code> &#x4EE5;&#x53CA; <code>aws_instance.b</code> &#x4E24;&#x79CD;&#x5730;&#x5740;&#x7684;&#x8D44;&#x6E90;&#x90FD;&#x5F97;&#x5230;&#x6210;&#x529F;&#x66F4;&#x65B0;&#xFF0C;Terraform &#x4F1A;&#x5C06;&#x4ED6;&#x4EEC;&#x89C6;&#x4F5C;&#x4ECE;&#x4E00;&#x5F00;&#x59CB;&#x5C31;&#x662F;&#x4EE5; <code>aws_instance.c</code> &#x7684;&#x5730;&#x5740;&#x521B;&#x5EFA;&#x7684;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="4.3.模块元参数.html" class="navigation navigation-prev " aria-label="Previous page: 模块元参数">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.5.设计新模块的模式.html" class="navigation navigation-next " aria-label="Next page: 设计新模块的模式">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"重构","level":"1.5.4","depth":2,"next":{"title":"设计新模块的模式","level":"1.5.5","depth":2,"path":"4.5.设计新模块的模式.md","ref":"./4.5.设计新模块的模式.md","articles":[]},"previous":{"title":"模块元参数","level":"1.5.3","depth":2,"path":"4.3.模块元参数.md","ref":"./4.3.模块元参数.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-highlight","prism","prism-themes","fontsettings","sharing","-lunr","-search","search-pro","livereload","image-captions","sitemap-general","anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prism-themes/themes/prism-vsc-dark-plus.css"],"lang":{"shell":"bash","cmd":"bash"}},"livereload":{},"search-pro":{},"sitemap-general":{"prefix":"https://lonegunmanb.github.io/introduction-terraform/"},"fontsettings":{"family":"sans","size":2,"theme":"white"},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"prism-themes":{},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"image-captions":{"caption":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","variable_name":"_pictures"}},"theme":"default","author":"大可不加冰","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[{"backlink":"index.html#fig1.1.1","level":"1.1","list_caption":"Figure: Nomad、Consul、Vault、Terraform 组成的 HashiStack","alt":"Nomad、Consul、Vault、Terraform 组成的 HashiStack","nro":1,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-13/1605243540985-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Nomad、Consul、Vault、Terraform 组成的 HashiStack","attributes":{},"skip":false,"key":"1.1.1"},{"backlink":"index.html#fig1.1.2","level":"1.1","list_caption":"Figure: Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","alt":"Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","nro":2,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-12-23/1608689176373-image.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","attributes":{},"skip":false,"key":"1.1.2"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.1","level":"1.3.1","list_caption":"Figure: Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","alt":"Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","nro":3,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-16/1605496195438-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","attributes":{},"skip":false,"key":"1.3.1.1"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.2","level":"1.3.1","list_caption":"Figure: registry.terraform.io上的插件页面","alt":"registry.terraform.io上的插件页面","nro":4,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-19/1605799350775-image.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"registry.terraform.io上的插件页面","attributes":{},"skip":false,"key":"1.3.1.2"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.3","level":"1.3.1","list_caption":"Figure: registry.terraform.io的搜索页面","alt":"registry.terraform.io的搜索页面","nro":5,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-16/1605498907942-image.png","index":3,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"registry.terraform.io的搜索页面","attributes":{},"skip":false,"key":"1.3.1.3"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.1","level":"1.3.2","list_caption":"Figure: Consul的GUI界面","alt":"Consul的GUI界面","nro":6,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220224455.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul的GUI界面","attributes":{},"skip":false,"key":"1.3.2.1"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.2","level":"1.3.2","list_caption":"Figure: Consul 中可以看到名为 `localstack-aws` 的键","alt":"Consul 中可以看到名为 `localstack-aws` 的键","nro":7,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230042.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul 中可以看到名为 `localstack-aws` 的键","attributes":{},"skip":false,"key":"1.3.2.2"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.3","level":"1.3.2","list_caption":"Figure: 键的内容","alt":"键的内容","nro":8,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230136.png","index":3,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"键的内容","attributes":{},"skip":false,"key":"1.3.2.3"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.4","level":"1.3.2","list_caption":"Figure: 键依然存在","alt":"键依然存在","nro":9,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230312.png","index":4,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"键依然存在","attributes":{},"skip":false,"key":"1.3.2.4"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.5","level":"1.3.2","list_caption":"Figure: 内容已被清空","alt":"内容已被清空","nro":10,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230350.png","index":5,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"内容已被清空","attributes":{},"skip":false,"key":"1.3.2.5"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.6","level":"1.3.2","list_caption":"Figure: 多了一个同名的文件夹","alt":"多了一个同名的文件夹","nro":11,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100309.png","index":6,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"多了一个同名的文件夹","attributes":{},"skip":false,"key":"1.3.2.6"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.7","level":"1.3.2","list_caption":"Figure: localstack-aws 文件夹内部","alt":"localstack-aws 文件夹内部","nro":12,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100354.png","index":7,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"localstack-aws 文件夹内部","attributes":{},"skip":false,"key":"1.3.2.7"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.8","level":"1.3.2","list_caption":"Figure: `.lock` 内容","alt":"`.lock` 内容","nro":13,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180803.png","index":8,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`.lock` 内容","attributes":{},"skip":false,"key":"1.3.2.8"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.9","level":"1.3.2","list_caption":"Figure: `.lockinfo` 内容","alt":"`.lockinfo` 内容","nro":14,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180852.png","index":9,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`.lockinfo` 内容","attributes":{},"skip":false,"key":"1.3.2.9"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.10","level":"1.3.2","list_caption":"Figure: 重新访问Consul","alt":"重新访问Consul","nro":15,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225101100.png","index":10,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"重新访问Consul","attributes":{},"skip":false,"key":"1.3.2.10"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.11","level":"1.3.2","list_caption":"Figure: 将代码复制到不同的文件夹中保存","alt":"将代码复制到不同的文件夹中保存","nro":16,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-17/1605571444613-image.png","index":11,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"将代码复制到不同的文件夹中保存","attributes":{},"skip":false,"key":"1.3.2.11"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.12","level":"1.3.2","list_caption":"Figure: 重新访问 Consul，目前有一个键","alt":"重新访问 Consul，目前有一个键","nro":17,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225174932.png","index":12,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"重新访问 Consul，目前有一个键","attributes":{},"skip":false,"key":"1.3.2.12"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.13","level":"1.3.2","list_caption":"Figure: Consul 中多了一个 `localstack-aws-env:feature1`","alt":"Consul 中多了一个 `localstack-aws-env:feature1`","nro":18,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175538.png","index":13,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul 中多了一个 `localstack-aws-env:feature1`","attributes":{},"skip":false,"key":"1.3.2.13"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.14","level":"1.3.2","list_caption":"Figure: 此时 `localstack-aws-env:feature1` 的内容","alt":"此时 `localstack-aws-env:feature1` 的内容","nro":19,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175806.png","index":14,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"此时 `localstack-aws-env:feature1` 的内容","attributes":{},"skip":false,"key":"1.3.2.14"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.15","level":"1.3.2","list_caption":"Figure: `localstack-aws-env:feature1` 被删除了","alt":"`localstack-aws-env:feature1` 被删除了","nro":20,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180126.png","index":15,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`localstack-aws-env:feature1` 被删除了","attributes":{},"skip":false,"key":"1.3.2.15"},{"backlink":"./5.10.graph.html#fig1.6.10.1","level":"1.6.10","list_caption":"Figure: 生成的依赖图","alt":"生成的依赖图","nro":21,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-25/1606272727693-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"生成的依赖图","attributes":{},"skip":false,"key":"1.6.10.1"},{"backlink":"8.CloudPosse最佳实践.html#fig1.9.1","level":"1.9","list_caption":"Figure: Terraform 输出值的命名要对称","alt":"Terraform 输出值的命名要对称","nro":22,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2021-11-28/1638086002974-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform 输出值的命名要对称","attributes":{},"skip":false,"key":"1.9.1"}]},"title":"《Terraform入门教程》","gitbook":"*"},"file":{"path":"4.4.重构.md","mtime":"2024-05-26T11:11:33.715Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-06-24T12:39:39.308Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    

    </body>
</html>

